﻿Imports System
Imports System.Data.OleDb
Imports System.Data

Public Class Provider
    Shared m_strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=PhanCongGiaoVien.mdb"
    Shared m_connection As OleDbConnection

    Public Shared Sub Open()
        If m_connection Is Nothing Then
            m_connection = New OleDbConnection(m_strConnection)
        End If
        m_connection.Open()

    End Sub

    Public Shared Sub Close()
        m_connection.Close()
    End Sub

    Public Shared Sub ExecNoneQuery(ByVal strSQL As String)
        Open()
        Dim _command As OleDbCommand
        _command = New OleDbCommand(strSQL, m_connection)
        Try
            _command.ExecuteNonQuery()
        Catch ex As OleDbException
            MessageBox.Show(ex.ToString())
        End Try
        Close()
    End Sub

    Public Shared Function ExecQuery(ByVal strSQL As String) As DataTable
        Open()
        Dim _adapter As New OleDbDataAdapter
        _adapter = New OleDbDataAdapter(strSQL, m_connection)
        Dim _dt As New DataTable()
        _dt.Clear()
        Try
            _adapter.Fill(_dt)
        Catch e As OleDbException
            MessageBox.Show(e.ToString())
        End Try
        Close()
        Return _dt
    End Function
End Class
